import { IPSSysDBScheme } from '../../database/ipssys-dbscheme';
import { IPSSysDBTable } from '../../database/ipssys-dbtable';
import { IPSDELogic } from './ipsdelogic';
import { IPSDELogicParam } from './ipsdelogic-param';
import { IPSDESysDBTableActionLogic } from './ipsdesys-dbtable-action-logic';
import { PSDELogicNodeImpl } from './psdelogic-node-impl';

export class PSDESysDBTableActionLogicImpl extends PSDELogicNodeImpl implements IPSDESysDBTableActionLogic {
  get dBTableAction(): 'CREATE' | 'UPDATE' | 'READ' | 'DELETE' {
    return this.M.dBTableAction;
  }

  protected dstpsdelogicparam: IPSDELogicParam | null = null;

  getDstPSDELogicParam(): IPSDELogicParam | null {
    if (this.dstpsdelogicparam != null) return this.dstpsdelogicparam;
    const value = this.M.getDstPSDELogicParam;
    if (value == null) {
      return null;
    }
    const ipsdelogic = this.getParentPSModelObject('dataentity.logic.IPSDELogic') as IPSDELogic;
    if (ipsdelogic != null) {
      this.dstpsdelogicparam = ipsdelogic.findPSDELogicParam(value);
    }
    return this.dstpsdelogicparam;
  }

  get dstPSDELogicParam(): IPSDELogicParam | null {
    return this.getDstPSDELogicParam();
  }

  getDstPSDELogicParamMust(): IPSDELogicParam {
    const value = this.getDstPSDELogicParam();
    if (value == null) {
      throw new Error('未指定目标逻辑参数对象');
    }
    return value;
  }

  protected pssysdbscheme: IPSSysDBScheme | null = null;

  getPSSysDBScheme(): IPSSysDBScheme | null {
    if (this.pssysdbscheme != null) return this.pssysdbscheme;
    const value = this.M.getPSSysDBScheme;
    if (value == null) {
      return null;
    }
    this.pssysdbscheme = this.getPSModel4('database.IPSSysDBScheme', value, 'getPSSysDBScheme') as IPSSysDBScheme;
    return this.pssysdbscheme;
  }

  get psSysDBScheme(): IPSSysDBScheme | null {
    return this.getPSSysDBScheme();
  }

  getPSSysDBSchemeMust(): IPSSysDBScheme {
    const value = this.getPSSysDBScheme();
    if (value == null) {
      throw new Error('未指定数据库体系');
    }
    return value;
  }

  protected pssysdbtable: IPSSysDBTable | null = null;

  getPSSysDBTable(): IPSSysDBTable | null {
    if (this.pssysdbtable != null) return this.pssysdbtable;
    const value = this.M.getPSSysDBTable;
    if (value == null) {
      return null;
    }
    const ipssysdbscheme = this.getPSSysDBScheme();
    if (ipssysdbscheme != null) {
      this.pssysdbtable = ipssysdbscheme.findPSSysDBTable(value);
    }
    return this.pssysdbtable;
  }

  get psSysDBTable(): IPSSysDBTable | null {
    return this.getPSSysDBTable();
  }

  getPSSysDBTableMust(): IPSSysDBTable {
    const value = this.getPSSysDBTable();
    if (value == null) {
      throw new Error('未指定数据表');
    }
    return value;
  }

  get cls(): string {
    return 'PSDESysDBTableActionLogicImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.logic.IPSDESysDBTableActionLogic') return true;
    return super.instanceof(cls);
  }
}
